package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.ShoppingCart;
import top.tsyz.service.IShoppingCartService;

import java.util.List;

/**
 * ShoppingCartController控制器
 */
@RestController
@RequestMapping("/api/shoppingCarts")
@Api(tags = "ShoppingCart管理接口")
public class ShoppingCartController {

    @Autowired
    private IShoppingCartService ishoppingcartservice;

    @GetMapping("/list")
    @ApiOperation("获取所有ShoppingCart")
    public List<ShoppingCart> list() {
        return ishoppingcartservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取ShoppingCart")
    public ShoppingCart getById(@PathVariable Long id) {
        return ishoppingcartservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增ShoppingCart")
    public boolean save(@RequestBody ShoppingCart shoppingcart) {
        return ishoppingcartservice.save(shoppingcart);
    }

    @PutMapping
    @ApiOperation("更新ShoppingCart")
    public boolean update(@RequestBody ShoppingCart shoppingcart) {
        return ishoppingcartservice.updateById(shoppingcart);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除ShoppingCart")
    public boolean delete(@PathVariable Long id) {
        return ishoppingcartservice.removeById(id);
    }
}
